package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.CheckPwdEntity
import com.dgshanger.sanhxiaofeisc.entity.LoosePaymentEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.PayModelSettingContract
import com.dgshanger.sanhxiaofeisc.mvp.model.PayModelSettingModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/4/20.
 */
class PayModelSettingPresenter : BaseMvpPresenter<PayModelSettingContract.Model, PayModelSettingContract.View>(), PayModelSettingContract.Presenter {

    override fun goPay(shop_id: String?, pay_amount: String?, pay_type: String?, user_pay_pwd: String?
                       , user_wallet_amount: String?, user_integral_amount: String?) {
        getModel().goPay(shop_id,pay_amount,pay_type,user_pay_pwd,user_wallet_amount,user_integral_amount
                , object : XxBaseHttpObserver<LoosePaymentEntity>(){
            override fun onCompleted(msg: String?, entity: LoosePaymentEntity?) {
                getView()?.showToast(msg)
                getView()?.onPaySuccess(entity)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog()
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun checkPwd() {
        getModel().checkPwd(object : XxBaseHttpObserver<CheckPwdEntity>(){
            override fun onCompleted(msg: String?, entity: CheckPwdEntity?) {
                if ("0"==entity!!.pwd_status){
                    getView()?.settingPwd()
                }else{
                    getView()?.showPwdDialog()
                }
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog()
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun createModel(): PayModelSettingContract.Model = PayModelSettingModel()
}